{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     1.0\n",
       "1     2.0\n",
       "2     3.0\n",
       "3     NaN\n",
       "4    33.0\n",
       "5    12.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series([1,2,3,np.nan,33,12])\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2019-01-18', '2019-01-19', '2019-01-20', '2019-01-21',\n",
       "               '2019-01-22', '2019-01-23', '2019-01-24'],\n",
       "              dtype='datetime64[ns]', freq='D')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates = pd.date_range('20190118',periods=7)\n",
    "dates\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(np.random.randn(7,4),index=dates,columns=['a','b','e','f'])#随机生成一个7行4列的数据，行名dates，列名abef"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>e</th>\n",
       "      <th>f</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-18</th>\n",
       "      <td>1.171935</td>\n",
       "      <td>0.717105</td>\n",
       "      <td>-0.022700</td>\n",
       "      <td>-2.636491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-19</th>\n",
       "      <td>-1.916398</td>\n",
       "      <td>0.751089</td>\n",
       "      <td>-0.087885</td>\n",
       "      <td>-0.046559</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-20</th>\n",
       "      <td>-0.186130</td>\n",
       "      <td>-0.901463</td>\n",
       "      <td>1.602896</td>\n",
       "      <td>-0.557870</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-21</th>\n",
       "      <td>-1.337498</td>\n",
       "      <td>0.242093</td>\n",
       "      <td>-0.427241</td>\n",
       "      <td>0.937158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-22</th>\n",
       "      <td>0.778036</td>\n",
       "      <td>0.574996</td>\n",
       "      <td>-0.169473</td>\n",
       "      <td>0.466328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-23</th>\n",
       "      <td>1.277110</td>\n",
       "      <td>0.225128</td>\n",
       "      <td>2.053643</td>\n",
       "      <td>-1.663049</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-24</th>\n",
       "      <td>1.949931</td>\n",
       "      <td>0.233890</td>\n",
       "      <td>0.437913</td>\n",
       "      <td>0.598839</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   a         b         e         f\n",
       "2019-01-18  1.171935  0.717105 -0.022700 -2.636491\n",
       "2019-01-19 -1.916398  0.751089 -0.087885 -0.046559\n",
       "2019-01-20 -0.186130 -0.901463  1.602896 -0.557870\n",
       "2019-01-21 -1.337498  0.242093 -0.427241  0.937158\n",
       "2019-01-22  0.778036  0.574996 -0.169473  0.466328\n",
       "2019-01-23  1.277110  0.225128  2.053643 -1.663049\n",
       "2019-01-24  1.949931  0.233890  0.437913  0.598839"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>e</th>\n",
       "      <th>f</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>7.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>7.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.248141</td>\n",
       "      <td>0.263263</td>\n",
       "      <td>0.483879</td>\n",
       "      <td>-0.414521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1.442054</td>\n",
       "      <td>0.562802</td>\n",
       "      <td>0.962550</td>\n",
       "      <td>1.309055</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-1.916398</td>\n",
       "      <td>-0.901463</td>\n",
       "      <td>-0.427241</td>\n",
       "      <td>-2.636491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-0.761814</td>\n",
       "      <td>0.229509</td>\n",
       "      <td>-0.128679</td>\n",
       "      <td>-1.110459</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.778036</td>\n",
       "      <td>0.242093</td>\n",
       "      <td>-0.022700</td>\n",
       "      <td>-0.046559</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.224522</td>\n",
       "      <td>0.646050</td>\n",
       "      <td>1.020404</td>\n",
       "      <td>0.532583</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.949931</td>\n",
       "      <td>0.751089</td>\n",
       "      <td>2.053643</td>\n",
       "      <td>0.937158</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              a         b         e         f\n",
       "count  7.000000  7.000000  7.000000  7.000000\n",
       "mean   0.248141  0.263263  0.483879 -0.414521\n",
       "std    1.442054  0.562802  0.962550  1.309055\n",
       "min   -1.916398 -0.901463 -0.427241 -2.636491\n",
       "25%   -0.761814  0.229509 -0.128679 -1.110459\n",
       "50%    0.778036  0.242093 -0.022700 -0.046559\n",
       "75%    1.224522  0.646050  1.020404  0.532583\n",
       "max    1.949931  0.751089  2.053643  0.937158"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes\n",
    "df.columns\n",
    "df.index\n",
    "df.values\n",
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>f</th>\n",
       "      <th>e</th>\n",
       "      <th>b</th>\n",
       "      <th>a</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-18</th>\n",
       "      <td>-2.636491</td>\n",
       "      <td>-0.022700</td>\n",
       "      <td>0.717105</td>\n",
       "      <td>1.171935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-19</th>\n",
       "      <td>-0.046559</td>\n",
       "      <td>-0.087885</td>\n",
       "      <td>0.751089</td>\n",
       "      <td>-1.916398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-20</th>\n",
       "      <td>-0.557870</td>\n",
       "      <td>1.602896</td>\n",
       "      <td>-0.901463</td>\n",
       "      <td>-0.186130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-21</th>\n",
       "      <td>0.937158</td>\n",
       "      <td>-0.427241</td>\n",
       "      <td>0.242093</td>\n",
       "      <td>-1.337498</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-22</th>\n",
       "      <td>0.466328</td>\n",
       "      <td>-0.169473</td>\n",
       "      <td>0.574996</td>\n",
       "      <td>0.778036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-23</th>\n",
       "      <td>-1.663049</td>\n",
       "      <td>2.053643</td>\n",
       "      <td>0.225128</td>\n",
       "      <td>1.277110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-24</th>\n",
       "      <td>0.598839</td>\n",
       "      <td>0.437913</td>\n",
       "      <td>0.233890</td>\n",
       "      <td>1.949931</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   f         e         b         a\n",
       "2019-01-18 -2.636491 -0.022700  0.717105  1.171935\n",
       "2019-01-19 -0.046559 -0.087885  0.751089 -1.916398\n",
       "2019-01-20 -0.557870  1.602896 -0.901463 -0.186130\n",
       "2019-01-21  0.937158 -0.427241  0.242093 -1.337498\n",
       "2019-01-22  0.466328 -0.169473  0.574996  0.778036\n",
       "2019-01-23 -1.663049  2.053643  0.225128  1.277110\n",
       "2019-01-24  0.598839  0.437913  0.233890  1.949931"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_index(axis=1,ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>e</th>\n",
       "      <th>f</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-18</th>\n",
       "      <td>1.171935</td>\n",
       "      <td>0.717105</td>\n",
       "      <td>-0.022700</td>\n",
       "      <td>-2.636491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-23</th>\n",
       "      <td>1.277110</td>\n",
       "      <td>0.225128</td>\n",
       "      <td>2.053643</td>\n",
       "      <td>-1.663049</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-20</th>\n",
       "      <td>-0.186130</td>\n",
       "      <td>-0.901463</td>\n",
       "      <td>1.602896</td>\n",
       "      <td>-0.557870</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-19</th>\n",
       "      <td>-1.916398</td>\n",
       "      <td>0.751089</td>\n",
       "      <td>-0.087885</td>\n",
       "      <td>-0.046559</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-22</th>\n",
       "      <td>0.778036</td>\n",
       "      <td>0.574996</td>\n",
       "      <td>-0.169473</td>\n",
       "      <td>0.466328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-24</th>\n",
       "      <td>1.949931</td>\n",
       "      <td>0.233890</td>\n",
       "      <td>0.437913</td>\n",
       "      <td>0.598839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-21</th>\n",
       "      <td>-1.337498</td>\n",
       "      <td>0.242093</td>\n",
       "      <td>-0.427241</td>\n",
       "      <td>0.937158</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   a         b         e         f\n",
       "2019-01-18  1.171935  0.717105 -0.022700 -2.636491\n",
       "2019-01-23  1.277110  0.225128  2.053643 -1.663049\n",
       "2019-01-20 -0.186130 -0.901463  1.602896 -0.557870\n",
       "2019-01-19 -1.916398  0.751089 -0.087885 -0.046559\n",
       "2019-01-22  0.778036  0.574996 -0.169473  0.466328\n",
       "2019-01-24  1.949931  0.233890  0.437913  0.598839\n",
       "2019-01-21 -1.337498  0.242093 -0.427241  0.937158"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values(by='f')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
